"""
ASGI config for application project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

# import os
#
# from django.core.asgi import get_asgi_application
#
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
# os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
#
# from application.websocketConfig import websocket_application
#
# http_application = get_asgi_application()
#
# async def application(scope,receive,send):
#     if scope['type'] == 'http':
#         await http_application(scope, receive, send)
#     elif scope['type'] == 'websocket':
#         await websocket_application(scope, receive, send)
#     else:
#         raise Exception("未知的scope类型,"+ scope['type'])



import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
django.setup()

from django.core.asgi import get_asgi_application

from dvadmin.utils.middleware import JwtAuthMiddleware
from channels.routing import ProtocolTypeRouter, URLRouter
from dvadmin.lywebsocket.routing import websocket_urlpatterns


# application = get_asgi_application()

application = ProtocolTypeRouter({
  "http": get_asgi_application(),# 也可以不需要此项，普通的HTTP请求不需要我们手动在这里添加，框架会自动加载
  "websocket": JwtAuthMiddleware(
        # 多个url合并一起使用，多个子路由列表相加:a+b
        URLRouter(
            websocket_urlpatterns
        )
    ),
})
